﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;
using Actuals.Data;

namespace Actuals.Business
{
    public class BusinessEmployee : IBusinessEmployee
    {

        private IDalEmployee _dalEmployee;

        public BusinessEmployee(IDalEmployee dalEmployee)
        {
            _dalEmployee = dalEmployee;
        }

        public BusinessEmployee()
        {
            _dalEmployee = new DalEmployee();
        }

        public IList<IEmployee> GetEmployees()
        {
            return _dalEmployee.GetEmployees();
        }
        
        public IEmployee GetEmployee(int employeeId)
        {
            return _dalEmployee.GetEmployee(employeeId);
        }

        public IList<IProject> GetProject(int employeeId)
        {
            IBusinessTeamMember businessTeamMember = new BusinessTeamMember();
            IList<ITeamMember> teamMembers = businessTeamMember.GetTeamMemberByEmployee(employeeId);

            IBusinessProject businessProject = new BusinessProject();
            List<IProject> projects = businessProject.GetProjects();

            List<IProject> empProjects = new List<IProject>();

            foreach (ITeamMember teamMember in teamMembers)
            {
                IList<IProject> _projects = projects.FindAll(delegate(IProject project) { return project.TeamId == teamMember.TeamId; });
                foreach (IProject _project in _projects)
                {
                    if (!empProjects.Contains(_project))
                        empProjects.Add(_project);
                }
            }
                    
          

            return empProjects;
        }

        public void AddEmployee(IEmployee employee)
        {
            _dalEmployee.AddEmployee(employee);
        }

        public void DeleteEmployee(int employeeId)
        {
            _dalEmployee.DeleteEmployee(employeeId);
        }

        public void UpdateEmployee(IEmployee employee)
        {
            _dalEmployee.UpdateEmployee(employee);
        }
    }
}
